using System;
using Life.ESound;
using Life.ESound.Bridge;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Events;

namespace Samples.Unity_Dev_Extern._1._0._0.Utils
{
        public class OtherEffectPlayer : MonoBehaviour
        {
#if UNITY_EDITOR && UNITY_WEBGL
                [OnValueChanged("OnAudioClip")]
#endif
                [SerializeField]
                private AudioClip audioClip;

#if UNITY_WEBGL
                [SerializeField] [ReadOnly] private float audioLength;
                public float AudioLength => audioLength;
#else
                public float AudioLength => audioClip ? audioClip.length : 0;
#endif
            [SerializeField] private UnityEvent onEffectPlay = new UnityEvent();
            public UnityEvent OnEffectPlay => onEffectPlay;

#if UNITY_EDITOR && UNITY_WEBGL
                void OnAudioClip()
                {
                    audioLength = audioClip ? audioClip.length : 0;
                }
#endif
            public void Play()
            {
                ESoundBridge.PlayEffect(audioClip);
                onEffectPlay?.Invoke();
            }
        }
}
